local qingwu = fk.CreateSkill {
  name = "lingling__qingwu",
}
local U = require "packages/utility/utility"
Fk:loadTranslationTable {
  ["lingling__qingwu"] = "卿舞",
  [":lingling__qingwu"] = "当你体力减少后，你摸X张牌；当你体力增加后，你摸一张牌。（X为本轮你体力值变化次数，且至多为3）",

  ["#lingling__qingwu-invoke"] = "卿舞：你可以摸%arg张牌！",
}

qingwu:addEffect(fk.HpChanged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(qingwu.name) and data.who == player
  end,
  on_cost = function(self, event, target, player, data)
    local num = 1
    if data.num < 0 then
      num = player:getMark("lingling__qingwu-round")
    end
    return player.room:askToSkillInvoke(player, {
      skill_name = qingwu.name,
      prompt = "#lingling__qingwu-invoke:::" .. U.ConvertNumber(num)
    })
  end,
  on_use = function(self, event, target, player, data)
    local num = 1
    if data.num < 0 then
      num = player:getMark("lingling__qingwu-round")
    end
    player:drawCards(num, qingwu.name)
  end,

  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(qingwu.name, true) and data.who == player and player:getMark("lingling__qingwu-round") < 3
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "lingling__qingwu-round", 1)
  end
})

return qingwu
